<%@ page contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" errorPage="/error.jsp"%>
<%@page import="dbexp.model.View"%>
<%@page import="dbexp.model.db.DbUser"%>
<%@page import="dbexp.connection.DbMetaData"%>
<%@page import="dbexp.connection.DbConnection"%>
<%@page import="org.json.JSONObject"%>
<%
DbUser u = (DbUser)session.getAttribute("USER");
String name = request.getParameter("name");
String schema = request.getParameter("schema");
String source = request.getParameter("source");
String action = request.getParameter("action");
boolean brak = (name==null || name.trim().equals("null")) && (schema==null || schema.trim().equals("null"));
View ob =  new View(name,schema);
if(!brak && action.equals("create")||action.equals("update")){
ob.setContent(source);
	int status = DbMetaData.operateObject(u,ob,DbConnection.CREATE);
}
	ob = DbMetaData.getView(u, name, schema);
out.clearBuffer();%><%=new JSONObject().
												put("success", true).
												put("data",new JSONObject().
														put("name", ob.getName()).
														put("schema",ob.getSchema()).
														put("source",ob.getContent()).
														put("errors",ob.getErrorString()))%>